MongoDB Schema Design for Generated Websites
Storing generated websites as one large blob is tempting. It is fast at the beginning and painful later. If users need previews, edits, regeneration, analytics, publishing, and version history, the schema needs to reflect those product behaviors.
Start from product operations
The database should support what the user can do. In IaGenify, a generated website may include pages, sections, components, assets, settings, publishing state, analytics references, and generation history. Those are not all the same kind of data.
A schema is good when it makes future product operations easier, not only when the first save works.
Before designing collections, I look at operations: create a website, regenerate one section, edit copy, publish, duplicate, track visits, restore a version, and display recent activity.
Entities worth separating
- Website: owner, name, domain state, theme, status, global settings.
- Page: route, title, SEO metadata, section order, page intent.
- Section: type, variant, content, component reference, layout rules.
- Asset: media URL, type, source, ownership, generated metadata.
- Generation event: prompt, model, cost, status, validation result.
This does not mean every entity needs a separate collection immediately. It means the data model should respect their different responsibilities.
Embedding versus referencing
MongoDB gives flexibility, but flexibility still needs discipline. Embedding can work for tightly coupled page sections. Referencing can work for reusable assets, analytics, or large histories. The right choice depends on access patterns.
Useful references include MongoDB data modeling documentation, Mongoose schema guide, and MongoDB schema design patterns.
CTA: Model edits, not only creation
If your product generates websites, design the schema around what happens after generation. Editing, publishing, analytics, and recovery are where the model is tested.
